package liuhao.user.service.impl;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.ibatis.session.SqlSession;

import liuhao.base.SessionUtil;
import liuhao.user.dao.UserDao;
import liuhao.user.entity.UserEntity;
import liuhao.user.service.UserService;

public class UserServiceImpl implements UserService {
	
	private static Set<String> count=new HashSet<String>();

	@Override
	public Map<String, Object> loginUser(UserEntity entity) {
		
		Map<String, Object> map=new HashMap<String, Object>();
		SqlSession session = SessionUtil.getSession();
		UserDao dao = session.getMapper(UserDao.class);
		try {
			UserEntity e = dao.loginUser(entity);
			count.add(entity.getUsername());
			int rs = count.size();
			if(null !=e){
				map.put("code", "200");
				map.put("rs",rs);
			
			}else{
				map.put("code", "444");
			}
			
		} catch (Exception e) {
			map.put("code", "444");
			e.printStackTrace();
		}
		
		return map;
	}

	@Override
	public Map<String, Object> fingUserbyName(UserEntity entity) {
		
		Map<String, Object> map=new HashMap<String, Object>();
		SqlSession session = SessionUtil.getSession();
		UserDao dao = session.getMapper(UserDao.class);
		try {
			UserEntity entity2 = dao.fingUserbyName(entity);
			
			if(null ==entity2){
				int addUser = dao.addUser(entity);
				map.put("code", "200");
			}else{
				map.put("code", "444");
			}
			
		} catch (Exception e) {
			map.put("code", "444");
			e.printStackTrace();
		}
		
		return map;
	}

	@Override
	public Map<String, Object> addUser(UserEntity entity) {
		return null;
	}

	@Override
	public Map<String, Object> updateUser(UserEntity entity) {
		// TODO Auto-generated method stub
		return null;
	}

	public void q(String a) {
		
		count.remove(a);
		System.out.println(count);
		
		
	}

}
